home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2003 March / DPPCPRO0303.ISO / Components / Microsoft ASP / _SETUP.1 / ASPComponents.jar / asp / nfx / MSDBQuery / MSDBQuery.class (.txt)
Encoding:
Java Class File  |  1998-11-20  |  9.0 KB  |  304 lines

  1. package asp.nfx.MSDBQuery;
  2.  
  3. import asp.util.EResourceUtil;
  4. import asp.util.ResourceUtil;
  5. import com.netobjects.nfc.api.CStringArray;
  6. import com.netobjects.nfc.api.ComponentApp;
  7. import com.netobjects.nfc.api.DAssetManager;
  8. import com.netobjects.nfc.api.DDrawPicture;
  9. import com.netobjects.nfc.api.DImage;
  10. import com.netobjects.nfc.api.DLayout;
  11. import com.netobjects.nfc.api.DMessageBox;
  12. import com.netobjects.nfc.api.DRect;
  13. import com.netobjects.nfc.api.DSize;
  14. import com.netobjects.nfc.api.IDInspector;
  15.  
  16. public class MSDBQuery extends ComponentApp {
  17.    String dbConnection;
  18.    String name;
  19.    int usePreviousQuery;
  20.    String select;
  21.    String from;
  22.    String where;
  23.    String orderBy;
  24.    private String INCLUDEFILE_SUBDIR = "asp";
  25.    DAssetManager assMan;
  26.    String codebase;
  27.    DDrawPicture component;
  28.    protected static transient ResourceUtil resUtil = null;
  29.    static final int MAXASSET = 50;
  30.    int[] assetControl;
  31.    int assetCount;
  32.    boolean published = false;
  33.    static final String SCRIPTDELIMOPEN = "<SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT>\n";
  34.    static final String SCRIPTDELIMCLOSE = "</SCRIPT>\n";
  35.    // $FF: synthetic field
  36.    static Class class$asp$nfx$MSDBQuery$MSDBQuery;
  37.  
  38.    public String onInstall(DAssetManager cam, String codebase) {
  39.       this.assMan = cam;
  40.       return "MSDBQuery";
  41.    }
  42.  
  43.    public void onDrop(DLayout layout, DRect r, int fDrop) {
  44.       if (fDrop == 1) {
  45.          this.dbConnection = new String("MSDBConnection1");
  46.          this.name = new String(resUtil.getString("value.name"));
  47.          this.usePreviousQuery = 1;
  48.          this.select = new String(resUtil.getString("value.select"));
  49.          this.from = new String(resUtil.getString("value.from"));
  50.          this.where = new String("");
  51.          this.orderBy = new String("");
  52.          this.assetControl = new int[50];
  53.          this.component = new DDrawPicture();
  54.          this.codebase = this.component.getCodeBase();
  55.          this.component.setImageFile(this.codebase + resUtil.getString("image.filename"));
  56.          this.component.SetStyle(1, 1);
  57.          this.component.setStretch(1);
  58.          this.component.SetPositionRect(r.getLeft(), r.getTop(), r.getRight(), r.getBottom());
  59.          this.resizeComponent(this.component);
  60.          layout.AddObject(this.component);
  61.       }
  62.    }
  63.  
  64.    public void onInspect(CStringArray Names, CStringArray Types) {
  65.       Names.Set(resUtil.getString("property.name"));
  66.       Types.Set("String");
  67.       Names.Set(resUtil.getString("property.useprev"));
  68.       Types.Set("Set(" + resUtil.getString("option.useprev") + ")");
  69.       Names.Set(resUtil.getString("property.select"));
  70.       Types.Set("String");
  71.       Names.Set(resUtil.getString("property.from"));
  72.       Types.Set("String");
  73.       Names.Set(resUtil.getString("property.where"));
  74.       Types.Set("String");
  75.       Names.Set(resUtil.getString("property.orderby"));
  76.       Types.Set("String");
  77.    }
  78.  
  79.    public String PropertyListener(String Event, String Value, int Get, int propIndex, IDInspector insp) {
  80.       if (Get == 1) {
  81.          if (Event.compareTo(resUtil.getString("property.name")) == 0) {
  82.             return this.name;
  83.          }
  84.  
  85.          if (Event.compareTo(resUtil.getString("property.useprev")) == 0) {
  86.             return Integer.toString(this.usePreviousQuery);
  87.          }
  88.  
  89.          if (Event.compareTo(resUtil.getString("property.select")) == 0) {
  90.             return this.select;
  91.          }
  92.  
  93.          if (Event.compareTo(resUtil.getString("property.from")) == 0) {
  94.             return this.from;
  95.          }
  96.  
  97.          if (Event.compareTo(resUtil.getString("property.where")) == 0) {
  98.             return this.where;
  99.          }
  100.  
  101.          if (Event.compareTo(resUtil.getString("property.orderby")) == 0) {
  102.             return this.orderBy;
  103.          }
  104.       } else {
  105.          if (Event.compareTo(resUtil.getString("property.name")) == 0 && this.isValidName(Value)) {
  106.             this.name = Value;
  107.          }
  108.  
  109.          if (Event.compareTo(resUtil.getString("property.useprev")) == 0) {
  110.             this.usePreviousQuery = Integer.parseInt(Value, 10);
  111.          }
  112.  
  113.          if (Event.compareTo(resUtil.getString("property.select")) == 0 && this.isValidName(Value)) {
  114.             this.select = Value;
  115.          }
  116.  
  117.          if (Event.compareTo(resUtil.getString("property.from")) == 0 && this.isValidName(Value)) {
  118.             this.from = Value;
  119.          }
  120.  
  121.          if (Event.compareTo(resUtil.getString("property.where")) == 0) {
  122.             this.where = Value;
  123.          }
  124.  
  125.          if (Event.compareTo(resUtil.getString("property.orderby")) == 0) {
  126.             this.orderBy = Value;
  127.          }
  128.       }
  129.  
  130.       return "";
  131.    }
  132.  
  133.    public void onCopy() {
  134.       this.codebase = new String(this.codebase);
  135.       int[] assetControlOld = this.assetControl;
  136.  
  137.       for(int i = 0; i < this.assetCount; ++i) {
  138.          this.assetControl[i] = assetControlOld[i];
  139.          if (this.assetControl[i] != 0) {
  140.             this.assMan.CopyAsset(this.assetControl[i]);
  141.          }
  142.       }
  143.  
  144.    }
  145.  
  146.    public void onPublish(DAssetManager cam, int context) {
  147.       this.removeAssets();
  148.       this.published = true;
  149.       int javaScriptAsset = this.assMan.AddAsset(this.codebase + "MSDBQuery.inc", "JavaScript", "assets\\lib");
  150.       this.assetControl[this.assetCount] = javaScriptAsset;
  151.       this.assMan.SetPublishAssetMode(this.assetControl[this.assetCount++], 453);
  152.       DLayout cidLayout = this.component.getLayout();
  153.       String NestedDir = "";
  154.       String homePath = cidLayout.GetHomePath();
  155.       if (homePath.compareTo("..\\") == 0) {
  156.          NestedDir = ".";
  157.       }
  158.  
  159.       String IncludeFile = "<!--#INCLUDE FILE=\"" + NestedDir + "./assets/lib/MSDBQuery.inc\"-->\n";
  160.       String HTMLHead = "\n";
  161.       HTMLHead = HTMLHead + "<SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT>\n\n";
  162.       HTMLHead = HTMLHead + "//" + resUtil.getString("text.comment") + "\n";
  163.       HTMLHead = HTMLHead + this.name + " = new MSDBQuery(\n";
  164.       HTMLHead = HTMLHead + "                  \"" + this.name + "\",\n";
  165.       HTMLHead = HTMLHead + "                  \"" + this.dbConnection + "\",\n";
  166.       HTMLHead = HTMLHead + "                  \"" + this.usePreviousQueryToString(this.usePreviousQuery) + "\",\n";
  167.       HTMLHead = HTMLHead + "                  \"" + this.select + "\",\n";
  168.       HTMLHead = HTMLHead + "                  \"" + this.from + "\",\n";
  169.       HTMLHead = HTMLHead + "                  \"" + this.where + "\",\n";
  170.       HTMLHead = HTMLHead + "                  \"" + this.orderBy + "\"\n";
  171.       HTMLHead = HTMLHead + "                  );\n";
  172.       HTMLHead = HTMLHead + "</SCRIPT>\n\n";
  173.       cidLayout.setHTMLBefore(IncludeFile + HTMLHead);
  174.       String theHTML = "\n<!--\n";
  175.       this.component.setHTMLBefore(theHTML);
  176.       this.component.setHTMLAfter("-->");
  177.    }
  178.  
  179.    protected void finalize() {
  180.       this.removeAssets();
  181.    }
  182.  
  183.    public void onUnInstall(DAssetManager cam) {
  184.    }
  185.  
  186.    private String usePreviousQueryToString(int value) {
  187.       switch (value) {
  188.          case 0:
  189.             return "true";
  190.          case 1:
  191.             return "false";
  192.          default:
  193.             return "false";
  194.       }
  195.    }
  196.  
  197.    private void removeAssets() {
  198.       if (this.published) {
  199.          for(int i = 0; i < this.assetCount; ++i) {
  200.             this.assMan.RemoveAsset(this.assetControl[i]);
  201.          }
  202.       }
  203.  
  204.       this.assetCount = 0;
  205.    }
  206.  
  207.    public boolean isValidName(String testString) {
  208.       boolean result = true;
  209.       if (testString.compareTo("") == 0) {
  210.          DMessageBox msg = new DMessageBox();
  211.          msg.Warning(resUtil.getString("error.validname"));
  212.          result = false;
  213.       }
  214.  
  215.       return result;
  216.    }
  217.  
  218.    private void resizeComponent(DDrawPicture aPict) {
  219.       DImage imageSizer = new DImage();
  220.       imageSizer.setImageFile(aPict.getImageFile());
  221.       DSize imageSize = imageSizer.getSize();
  222.       aPict.SetSize(imageSize.getWidth(), imageSize.getHeight());
  223.    }
  224.  
  225.    public static ResourceUtil initResourceUtil(Class compClass) {
  226.       ResourceUtil _ru = null;
  227.  
  228.       try {
  229.          _ru = new ResourceUtil("asp.nfx.res", compClass);
  230.       } catch (EResourceUtil e) {
  231.          System.err.println(((Throwable)e).getMessage());
  232.       }
  233.  
  234.       return _ru;
  235.    }
  236.  
  237.    public String propertyManager(String Event, String Value, int Get) {
  238.       if (Get == 1) {
  239.          if (Event.compareTo(resUtil.getString("property.name")) == 0) {
  240.             return this.name;
  241.          }
  242.  
  243.          if (Event.compareTo(resUtil.getString("property.useprev")) == 0) {
  244.             return Integer.toString(this.usePreviousQuery);
  245.          }
  246.  
  247.          if (Event.compareTo(resUtil.getString("property.select")) == 0) {
  248.             return this.select;
  249.          }
  250.  
  251.          if (Event.compareTo(resUtil.getString("property.from")) == 0) {
  252.             return this.from;
  253.          }
  254.  
  255.          if (Event.compareTo(resUtil.getString("property.where")) == 0) {
  256.             return this.where;
  257.          }
  258.  
  259.          if (Event.compareTo(resUtil.getString("property.orderby")) == 0) {
  260.             return this.orderBy;
  261.          }
  262.       } else {
  263.          if (Event.compareTo(resUtil.getString("property.name")) == 0 && this.isValidName(Value)) {
  264.             this.name = Value;
  265.          }
  266.  
  267.          if (Event.compareTo(resUtil.getString("property.useprev")) == 0) {
  268.             this.usePreviousQuery = Integer.parseInt(Value, 10);
  269.          }
  270.  
  271.          if (Event.compareTo(resUtil.getString("property.select")) == 0 && this.isValidName(Value)) {
  272.             this.select = Value;
  273.          }
  274.  
  275.          if (Event.compareTo(resUtil.getString("property.from")) == 0 && this.isValidName(Value)) {
  276.             this.from = Value;
  277.          }
  278.  
  279.          if (Event.compareTo(resUtil.getString("property.where")) == 0) {
  280.             this.where = Value;
  281.          }
  282.  
  283.          if (Event.compareTo(resUtil.getString("property.orderby")) == 0) {
  284.             this.orderBy = Value;
  285.          }
  286.       }
  287.  
  288.       return "";
  289.    }
  290.  
  291.    // $FF: synthetic method
  292.    static Class class$(String class$) {
  293.       try {
  294.          return Class.forName(class$);
  295.       } catch (ClassNotFoundException forName) {
  296.          throw new NoClassDefFoundError(((Throwable)forName).getMessage());
  297.       }
  298.    }
  299.  
  300.    static {
  301.       resUtil = initResourceUtil(class$asp$nfx$MSDBQuery$MSDBQuery != null ? class$asp$nfx$MSDBQuery$MSDBQuery : (class$asp$nfx$MSDBQuery$MSDBQuery = class$("asp.nfx.MSDBQuery.MSDBQuery")));
  302.    }
  303. }
  304.